﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1.DDD.Web.Default.login
{
    public class logAction  : Controller
	{
		#if (!AspNET && !MicrosoftOwin && !NFinalOwin)
		public logAction(HttpContext context):base(context){}
		public logAction(Microsoft.Owin.IOwinContext context):base(context){}
		public logAction(NFinal.Owin.HtmlWriter writer,NFinal.Owin.Request request):base(writer,request){}
		#endif
		#if AspNET
		public logAction(HttpContext context):base(context){}
		#endif
		#if MicrosoftOwin
		public logAction(Microsoft.Owin.IOwinContext context):base(context){}
		#endif
		#if NFinalOwin
		public logAction(string fileName, NFinal.Owin.Request request, NFinal.CompressMode compressMode) :base(fileName,request,compressMode){}
		public logAction(System.IO.Stream stream,NFinal.Owin.Request request, NFinal.CompressMode compressMode) : base(stream,request,compressMode) {}
		public logAction(System.Collections.Generic.IDictionary<string, object> enviroment, NFinal.Owin.Request request, NFinal.CompressMode compressMode):base(enviroment,request,compressMode){}
		#endif
		public logAction(Controller controller):base(controller){}
        
        [GetHtml("login/log")]
        public void log(string name,string pwd)
        {
            
var con = new System.Data.SQLite.SQLiteConnection(NFinal.Config.ConfigurationManager.ConnectionStrings["Common"].ConnectionString);
con.Open();

            
#region	var count; 选取首行首列的值
			var __log_count_command__ = new System.Data.SQLite.SQLiteCommand("select count(*) from users where name=@name and pwd=@pwd", con);
						var __log_count_parameters__=new System.Data.SQLite.SQLiteParameter[2];
			
			__log_count_parameters__[0] = new System.Data.SQLite.SQLiteParameter("@name",System.Data.DbType.String,2147483647);
			__log_count_parameters__[0].Value = name.WithDBNull();
			__log_count_parameters__[1] = new System.Data.SQLite.SQLiteParameter("@pwd",System.Data.DbType.String,2147483647);
			__log_count_parameters__[1].Value = pwd.WithDBNull();
						__log_count_command__.Parameters.AddRange(__log_count_parameters__);
						var count = __log_count_command__.ExecuteScalar().AsVar();
			__log_count_command__.Dispose();
			#endregion
			
            con.Close();
            if (count>0)
            {
                //保留用户状态，1.使用cookie加密，2.使用redis缓存。
                //NFinal的vNext版本不支持session,因为IIS在高并发访问时，IIS内存占用太大的话容易假死。
                //this.Success("登陆成功",Url.DDD_IndexController_Index(), 3);
            }
            else
            {
                this.Error("登陆失败",Url.DDD_login_show(), 3);
            }
        }
        
    }
}